﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using BLL;

namespace winUi
{
    public partial class fromdiclist : Form
    {
        public fromdiclist()
        {
            InitializeComponent();
        }

        private void fromdiclist_Load(object sender, EventArgs e)
        {
            dgvDic.SelectionMode = DataGridViewSelectionMode.FullRowSelect;
            dgvDic.MultiSelect = false;
        }

        private void button1_Click(object sender, EventArgs e)
        {
            string keyword = txtKey.Text;
            dgvDic.DataSource = new BllDic().GetByKey(keyword);
        }

        private void toolStripButton3_Click(object sender, EventArgs e)
        {
            if (dgvDic.CurrentRow != null)
            {
                int id = Convert.ToInt32(dgvDic.CurrentRow.Cells[0].Value);
                if (MessageBox.Show("确定要删除吗？", "", MessageBoxButtons.YesNo) == DialogResult.Yes)
                {
                    new BllDic().Delete(id);
                    LoadData();
                }
            }
            else
            {
                MessageBox.Show("没有选择要删除的数据");
            }
            
        }

        void LoadData()
        {
            dgvDic.DataSource = new BllDic().GetAll();
        }

        private void toolStripButton1_Click(object sender, EventArgs e)
        {
            new FormDic().ShowDialog();
        }
    }
}
